package co.com.ejb.stateful;

import java.util.List;

import javax.ejb.Stateful;

import co.com.ejb.singleton.PostActivate;
import co.com.ejb.singleton.PostConstruct;
import co.com.ejb.singleton.PreActivate;
import co.com.ejb.singleton.PreDestroy;
import co.com.ejb.singleton.PrePassivate;

/**
 * Session Bean implementation class ShoppingCartBean
 */
@Stateful(mappedName = "ShoppingCart")
public class ShoppingCartBean implements ShoppingCartBeanRemote, ShoppingCartBeanLocal {
	
	List<String> items;
    /**
     * Default constructor. 
     */
    public ShoppingCartBean() {
        // TODO Auto-generated constructor stub
    }
	@Override
	public List<String> getItems() {
		return items;
	}
	@Override
	public void addItem(String item) {
		items.add(item);
	}
	
	@PostConstruct
    public void postConstruct(){
    	System.out.println("1. post construct");
    }
    
    @PrePassivate
    public void prePassivate(){
    	System.out.println("2. Timner has expired, going to sleep");
    }
    
    @PreActivate
    public void preActivate(){
    	System.out.println("3. Wake UP... initializng no passivate fields");
    }
    
    @PostActivate
    public void postActivate(){
    	System.out.println("4. All set and ready again");
    }
    
    @Override
    @Remove
    public void closeSession() {
    	System.out.println("5. Bean is being removed");
    	
    }
    
    @PreDestroy
    public void preDestroy(){
    	System.out.println("6. Going to destroy");
    }
    

}
